#include "head.h"

MYSQL *initSql(pool_t *pool) {
    char mysql_user[64];
    char mysql_password[64];
    char mysql_sqlname[64];
    char mysql_host[64];
    memset(mysql_user, 0, sizeof(mysql_user));
    memset(mysql_password, 0, sizeof(mysql_password));
    memset(mysql_sqlname, 0, sizeof(mysql_sqlname));
    memset(mysql_host, 0, sizeof(mysql_host));
    getparameter("mysql_user", mysql_user);
    getparameter("mysql_password", mysql_password);
    getparameter("mysql_sqlname", mysql_sqlname);
    getparameter("mysql_host", mysql_host);

    pthread_mutex_lock(&pool->sql_lock);
    MYSQL *conn = mysql_init(NULL);
    if(!mysql_real_connect(conn, mysql_host, mysql_user, mysql_password, mysql_sqlname, 0, NULL, 0)) {
        printf("%s\n", mysql_error(conn));
        return NULL;
    }
    pthread_mutex_unlock(&pool->sql_lock);

    return conn;
}
